<template>
  <el-form :model="BindingForm" status-icon :rules="rules" ref="BindingApp"
           label-width="auto">
    <h2 class="region_title">绑定</h2>
    <el-form-item prop="accountId" label="账号Id">
      <el-input type="text" v-model="BindingForm.accountId"
                placeholder="群组名称"></el-input>
    </el-form-item>
    <el-form-item prop="accountName" label="用户名称">
      <el-input type="text" v-model="BindingForm.accountName"
                placeholder="用户名称"></el-input>
    </el-form-item>
  </el-form>
</template>
<script>
  export default {
    name: "BindingApp",
    data() {
      var valiAccountId = (rule, value, callback) => {
        if (value === ''){
          callback(new Error('账号不能为空'));
        }else {
          callback();
        }
      };
      var valiAccountName = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('名称不能为空'));
        } else {
          callback();
        }
      }
      return {
        BindingForm: {
          accountId: '',
          accountName: '',
          accountHomePage: ''
        },
        rules: {
          accountId: [{validator: valiAccountId, trigger: 'blur'}],
          accountName: [{validator: valiAccountName, trigger: 'blur'}]
        }
      };
    },
    methods: {
      binding(appId) {
        this.$refs['BindingApp'].validate((valid) => {
          console.log("this app id :"+appId)
          if (valid) {
            let url="/api/account/doBinding?appId="+appId
            this.$axios
              .post(url, {
                accountId: this.BindingForm.accountId,
                accountName: this.BindingForm.accountName,
                appId: appId
              })
              .then(success => {
                this.$message({
                  type: 'info',
                  message: "添加成功！"
                });
              }).catch(fail => {
              this.$message.error("添加失败")
            })
          } else {
            this.$message.error("编辑信息有误")
            return false;
          }
        });
      },
      resetForm() {
        this.$refs['BindingApp'].resetFields();
      }
    }
  }
</script>
